/*
 * Copyright 2010. 
 * 
 * This document may not be reproduced, distributed or used 
 * in any manner whatsoever without the expressed written 
 * permission of xrkol Corp. 
 * 
 * $Rev: Rev $
 * $Author: Author $
 * $LastChangedDate: LastChangedDate $
 *
 */

package com.xrkol.sharelib.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xrkol.sharelib.dao.ConversationDao;
import com.xrkol.sharelib.entity.Adult;
import com.xrkol.sharelib.entity.Conversation;
import com.xrkol.sharelib.entity.Teacher;

/**
 * @author peng.xia
 *
 */
@Repository
public class ConversationDaoImpl extends BaseDaoImpl<Conversation,String> implements ConversationDao{

    @Override
    public List<Conversation> getConversationsByTeacher(Teacher teacher,Integer page) {
        String queryString = "from Conversation c where c.teacher = ?";
        return executeQueryWithPagination(queryString, null, page, teacher);
    }

    @Override
    public Conversation getConversationByTeacherAndAdult(Teacher teacher, Adult adult) {
        String queryString = "from Conversation c where c.teacher = ? and c.adult = ?";
        List<Conversation> conversations=executeQueryWithoutPaging(queryString,teacher,adult);
        return conversations.size()>0?conversations.get(0):null;
    }

    @Override
    public List<Conversation> getConversationsByAdult(Adult adult) {
        String queryString = "from Conversation c where c.adult = ?";
        return executeQueryWithoutPaging(queryString, adult);
    }

}
